<html>
<head>
<script>
function base64DecodeToArrayBuffer(encoded) {
  // atob() decodes base64 strings into binary string.
  var decoded = atob(encoded); 
  var buffer = new ArrayBuffer(decoded.length);
  var view = new Uint8Array(buffer);
  for (var i = 0; i < decoded.length; i++) {
    view[i] = decoded.charCodeAt(i);
  }
  return buffer;
}

window.onload = function() {
  if (typeof chrome.setSyncEncryptionKeys == "undefined") {
    document.title = "UNDEFINED";
  } else {
    chrome.setSyncEncryptionKeys(() => { window.close(); },
                                 location.search.substring(1),
                                 [base64DecodeToArrayBuffer(location.hash.substring(1))],
                                 /*last_key_version=*/7);
  }
}
</script>
</head>
</html>
